package org.grow.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableDiscoveryClient
public class GatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }


//    http://localhost:9092/commodity/storage/intention
    public static String commodityApp = "lb://commodity";
    public static String leaveApp = "lb://leave";
    public static String safetyApp = "lb://safety";
    public static String billApp = "lb://bill";
    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder){
        return builder.routes()
                .route("商品资料模块",r->{
                    return r.path("/commodity/**")
                            .uri(commodityApp);
                })
                .route("人事请假模块",r->{
                    return r.path("/leave/**")
                            .uri(leaveApp);
                })
                .route("用户管理模块",r->{
                    return r.path("/safety/**")
                            .uri(safetyApp);
                })
                .route("特殊接口，登入",r->{
                    return r.path("/login")
                            .uri(safetyApp);
                })
                .route("特殊接口，登出",r->{
                    return r.path("/logout")
                            .uri(safetyApp);
                })
                .route("单据管理模块",r->{
                    return r.path("/bill/**")
                            .uri(billApp);
                })
                .build();
    }
}
